package com.miyu.rabbitmq.config;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.AcknowledgeMode;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageListener;
import org.springframework.stereotype.Component;

import java.nio.charset.StandardCharsets;
import java.util.List;

@Component
public class MessageListenerImpl implements MessageListener {
    private static final Logger logger = LoggerFactory.getLogger(MessageListenerImpl.class);
    /**
     * @param message
     */
    @Override
    public void onMessage(Message message) {

        String mes = new String(message.getBody(), StandardCharsets.UTF_8);
        System.out.println(message.getMessageProperties());
//        JSONObject jsonObject = JSONObject.parseObject(mes);
        logger.info("监听到消息:{}",mes);
        System.out.println(">>>>>>>>>"+mes);
        //todo 业务处理

    }

    /**
     * @param mode
     */
    @Override
    public void containerAckMode(AcknowledgeMode mode) {
        MessageListener.super.containerAckMode(mode);
    }

    /**
     * @return
     */
    @Override
    public boolean isAsyncReplies() {
        return MessageListener.super.isAsyncReplies();
    }

    /**
     * @param messages
     */
    @Override
    public void onMessageBatch(List<Message> messages) {
        MessageListener.super.onMessageBatch(messages);
    }
}
